// CoGetClassObject Client.cpp
// Use this client on Windows 2000 or Windows NT
#define _WIN32_DCOM
#include <iostream.h>
#include "Component\component.h"

void main()
{
	cout << "Client: Calling CoInitialize()" << endl;
	CoInitialize(NULL);
	
	HRESULT hr;
	ISum* pSum;

	IClassFactory* pClassFactory;

	cout << "Client: Calling CoGetClassObject()" << endl;
	hr = CoGetClassObject(CLSID_InsideCOM, CLSCTX_LOCAL_SERVER, NULL, IID_IClassFactory, (void**)&pClassFactory);
	if(FAILED(hr))
		cout << "CoGetClassObject FAILED" << endl;

	cout << "Client: Calling CreateInstace() pClassFactory = " << pClassFactory << endl;
	hr = pClassFactory->CreateInstance(NULL, IID_ISum, (void**)&pSum);
	if(FAILED(hr))
		cout << "CreateInstance FAILED" << endl;

	cout << "Client: Calling Release()" << endl;
	pClassFactory->Release();

	int sum;
	hr = pSum->Sum(2, 3, &sum);
	if(SUCCEEDED(hr))
		cout << "Client: Calling Sum() on " << pSum << " return value is " << sum << endl;

	hr = pSum->Sum(7, 8, &sum);
	if(SUCCEEDED(hr))
		cout << "Client: Calling Sum() on " << pSum << " return value is " << sum << endl;

	hr = pSum->Release();
	cout << "Client: Calling Release() for ISum on " << hr << endl;

	cout << "Client: Calling CoUninitialize()" << endl;
	CoUninitialize();
}